﻿using NUnit.Framework;

namespace IGS.Core.Tests
{
    public static class VectorTests
    {
        [TestFixture]
        public class GivenOneVector
        {
            [Test]
            public void WhenTheLengthIsCalculatedItShouldReturnTheEuclideanNorm()
            {
                // Arrange
                var v = new Vector(1, 2, 2);

                // Act
                var length = v.Length;
                
                // Assert
                Assert.AreEqual(3, length, "Length");
            }

            [Test]
            public void WhenToStringIsCalledTheCoordinatesShouldBeReturnedInAString()
            {
                // Arrange
                var v = new Vector(1, 2, 3);

                // Act
                var result = v.ToString();

                // Assert
                Assert.AreEqual("1.000 2.000 3.000", result, "Vector.ToString");
            }
        }

        [TestFixture]
        public class GivenVectorAndAScalar
        {
            [Test]
            public void WhenTheVectorIsMultipliedByTheScalarItShouldReturnTheScaledVector()
            {
                // Arrange
                const double s = 2.0;
                var v = new Vector(1, 2, 3);

                // Act
                var sv = s * v;

                // Assert
                Assert.AreEqual(sv.X, 2, "X");
                Assert.AreEqual(sv.Y, 4, "Y");
                Assert.AreEqual(sv.Z, 6, "Z");
            }
        }

        [TestFixture]
        public class GivenTwoVectors
        {
            [Test]
            public void WhenAddingVectorsShouldReturnVectorSum()
            {
                // Arrange
                var v1 = new Vector(1, 0, 0);
                var v2 = new Vector(0, 1, 1);

                // Act
                var result = v1 + v2;

                // Assert
                Assert.AreEqual(1, result.X, "X");
                Assert.AreEqual(1, result.Y, "Y");
                Assert.AreEqual(1, result.Z, "Z");
            }

            [Test]
            public void WhenSubtractingVectorsShouldReturnVectorDifference()
            {
                // Arrange
                var v1 = new Vector(0, 2, 2);
                var v2 = new Vector(-1, 1, 1);

                // Act
                var result = v1 - v2;

                // Assert
                Assert.AreEqual(1, result.X, "X");
                Assert.AreEqual(1, result.Y, "Y");
                Assert.AreEqual(1, result.Z, "Z");
            }

            [Test]
            public void WhenTwoVectorsAreComparedTheyShouldBeNumericallyCompared()
            {
                // Arrange
                var v1 = new Vector(1.0, 1.0, 1.0);
                var v2 = new Vector(1.0, 1.0, 1.0);

                // Act
                var result = v1.Equals(v2);

                // Assert
                Assert.IsTrue(result);
            }


        }
    }
}
